/*
 * This used to be the gui container for the Vision class.  Now it is merely
 * a thread container.
 * 
 * @author Dan
 */

package legoserver;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class LegoMazePathfinder extends Thread{
    
  private ServerGUI gui;
  
  private Vision app;
  
  private boolean running;
    
  public LegoMazePathfinder(ServerGUI gui) {
    this.gui = gui;
  }
  
  @Override
  public void run() {
    //Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    try {
        app = new Vision(this);
    }catch(Exception e) {
        e.printStackTrace();
        System.exit(0);
        return; //This is unnecessary, but keeps the compiler from whining
    }
    /*app.setBackground(Color.gray);
    app.setSize(app.mazeIcon.getIconWidth(),app.mazeIcon.getIconHeight());
    app.setResizable(false);
    app.setVisible(true);
    update("Ready and waiting for coordinates...");
    app.doAll();
    app.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) { System.exit(0); }
    });
    
    update("Closing...  An error occured.");*/
    
    running = true;
    while(running) {
        //keep thread alive, checking every 100 ms
        try {
            Thread.sleep(1000);
        }catch(InterruptedException e) {
            //keep on waiting.
        }
    }
  }
  
  public void shutdown() {
      running = false;
      
  }
  
  public boolean isRunning() {
      return running;
  }
  
  public void update(String s) {
      gui.update("Pathfinder: " +  s);
  }
  
  public boolean isBusy() {
      return app.isBusy();
  }
  
  public void printMap() {
      app.printMap();
  }
  
  /*public Vision getVision() {
      return app;
  }*/
  
  /*public void setCoords(Point start, Point stop) {
    app.setCoords(start, stop);
  }*/
  
  public void getPath(Image i, Point start, Point end) {
      app.doAStar(i, start, end);
  }
  
  public ServerGUI getGUI() {
      return gui;
  }
  
  public Vector getSolution() {
      return app.getSolution();
  }
  
  /*public void refreshImage(Image i) {
      app.refreshImage(i);
  }*/
}